home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / Maya_phong_postlighting_vert < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.6 KB  |  91 lines

  1. // phong_vertex.cg
  2. //
  3. // This file cannot be directly compiled through CG... it first must be
  4. // parsed to insert channel-specific instructions.
  5. //
  6.  
  7. struct vert2frag
  8. {
  9.     float4 hPosition            : POSITION;
  10.  
  11. #if defined(BUMP_MAP)
  12.     float3 wBinormal            : TEXCOORD0;
  13.     float3 wTangent                : TEXCOORD1;
  14.     float4 bumpTexUv            : TEXCOORD2;
  15. #else
  16.     float3 wNormal                : TEXCOORD0;
  17. #endif // BUMP_MAP
  18.     
  19.     float4 transpTexUv            : TEXCOORD3;
  20.     float4 incanTexUv            : TEXCOORD4;
  21.     float4 reflectivityTexUv    : TEXCOORD5;
  22.     float4 wPosition            : TEXCOORD6;
  23. };
  24.  
  25. // define inputs from application
  26. struct app2vert
  27. {
  28.     float4 position             : POSITION;
  29.     float4 normal               : NORMAL;
  30.  
  31. #ifdef BUMP_MAP
  32.     float4 tangent                : TEXCOORD0;
  33.     float4 bumpTexUv            : TEXCOORD1;
  34. #endif // BUMP_MAP
  35.  
  36.     float4 transpTexUv            : TEXCOORD2;
  37.     float4 incanTexUv            : TEXCOORD3;
  38.     float4 reflectivityTexUv    : TEXCOORD4;
  39. };
  40.  
  41. vert2frag main(app2vert IN, 
  42.                uniform float4x4 modelViewProj,                
  43.                uniform float4x4 objToWorldMatrix,
  44.                uniform float4x4 objToWorldMatrix_invtrans)
  45. {
  46.     vert2frag OUT;
  47.  
  48.     modelViewProj = glstate.matrix.mvp;
  49.  
  50.     // Compute the clip-space vertex position.
  51.     //
  52.     OUT.hPosition = mul(modelViewProj, IN.position);
  53.  
  54.     // Compute the world-space vertex position.
  55.     //
  56.     OUT.wPosition = mul(objToWorldMatrix, IN.position);
  57.  
  58.     // Copy the texture coordinates.
  59.     //
  60.     OUT.transpTexUv = IN.transpTexUv;
  61.     OUT.incanTexUv = IN.incanTexUv;
  62.     OUT.reflectivityTexUv = IN.reflectivityTexUv;
  63.  
  64.     // Compute the geometric normal, expressed in world space.
  65.     // Note: we pass in the tangent and binormal vector
  66.     // rather than the normal. Then in the fragment program,
  67.     // we recompute the normal using a cross-product. This ensures
  68.     // that we'll get the correct normal even when the model matrix
  69.     // has non-proportional scale, and it's cheaper than multiplying
  70.     // by the inverse-transpose.
  71.     //
  72. #ifdef BUMP_MAP
  73.     float3 oNormal = normalize(IN.normal.xyz);
  74.     float3 oBinormal = normalize(cross(oNormal, IN.tangent.xyz));
  75.     float3 oTangent = cross(oBinormal, oNormal);
  76.  
  77.     float3 wTangent = mul(objToWorldMatrix_invtrans, float4(oTangent, 0)).xyz;
  78.     OUT.wTangent = normalize(wTangent);
  79.  
  80.     float3 wBinormal = mul(objToWorldMatrix_invtrans, float4(oBinormal, 0)).xyz;
  81.     OUT.wBinormal = normalize(wBinormal);
  82.  
  83.     OUT.bumpTexUv = IN.bumpTexUv;
  84. #else
  85.     float4 oNormal = float4(normalize(IN.normal.xyz), 0);
  86.     OUT.wNormal = mul(objToWorldMatrix_invtrans, oNormal).xyz;
  87. #endif // BUMP_MAP
  88.  
  89.     return OUT;
  90. }
  91.